home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-09-02 | 6.9 KB | 172 lines | [TEXT/CCL2] |
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;check-menu.lisp
- ;;
- ;; Copyright © 1992 University of Toronto, Department of Computer Science
- ;; All Rights Reserved
- ;;
- ;; author: Mark A. Tapia
- ;;
- ;; Methods to support a new class of menus-items check-mark-menu-items.
- ;; A check-mark-menu-item remembers the check-mark character
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
- (in-package menus)
- (provide :check-menus)
-
- (export '(check-menu-item check-window-menu-item
- set-menu-item-check-mark set-check-mark-char
- containing-view)
- :menus)
-
- #|
- This file extends menus items to check-menu-items
-
- Check-menu-items ; a subclass of menu-items
- Check-menu-items store the check mark associated with them. The mark can
- be specified in three ways:
- 1. by specifying the mark when initializing the instance.
- (make-instance 'check-menu-item :mark #\CheckMark)
- which is equivalent to (make-instance 'check-menu-item :mark t)
- 2. by the set-check-mark-char method specifying a mark that is not t or nil.
- (set-check-mark-char check-menu-item mark)
- 3. by the set-menu-item-check-mark method specifying a mark that
- is not t or nil.
- (set-check-menu-item-check-mark check-menu-item mark)
- (set-menu-item-check-mark check-menu-item t) uses the previously
- specified check mark.
-
- Methods 1-2 do not check the item. Method 3 changes the character and checks
- the item.
-
- Use the initarg :mark to set the character (default #\checkMark)
- Use (set-check-mark char menu-item char) to set the character
- or (set-menu-item-check-mark menu-item char) where char is not t or nil
-
- check-menu-item ; a menu-item
- :initarg :mark ; default #\CheckMark
- specifies the character to be used as the marking character for
- the menu item.
-
- Mark may be t, a character, the character code of the character,
- or a string whose first character will be the checkmark character.
- Specifying any other value, uses the default #\CheckMark character
-
- The default mark is correctly printed when using the standard
- menu-font of Chicago but not with other fonts.
-
- Each of the menu-items created by the following instances specify
- the standard Chicago font checkmark character:
- (make-instance 'check-menu-item)
- (make-instance 'check-menu-item :mark t)
- (make-instance 'check-menu-item :mark #\CheckMark)
- (make-instance 'check-menu-item :mark "") ; the font is Chicago
- (make-instance 'check-menu-item :mark 18)
-
- check-window-menu-item ; a window-menu-item
- See check-menu-item
-
-
- Methods of interest
- (set-check-mark-char check-menu-item mark)
- sets the check mark character for the menu-item
- The mark may be
- 1. a character
- 2. an integer (0 - 255), where (code-char mark) is the character
- 3. a string, the first character of which is the marking character
-
- (set-menu-item-check-mark check-menu-item t)
- checks the item, using the mark associated with the menu-item
-
- (set-menu-item-check-mark check-menu-item nil)
- unchecks the item, but remembers the mark associated with a check
-
- (set-menu-item-check-mark check-menu-item mark)
- sets the mark (in one of the forms 1-3 above) and checks the menu-item
-
- Do-menu-item-action
- Performs the menu item action associated with the menu item.
-
- (do-menu-item-action check-menu-item)
- First checks or unchecks the item, removing/adding the check-mark.
- Then invokes the menu-item-action-function associated with the
- check-menu-item with no parameters.
-
- (do-menu-item-action window-menu-item)
- First checks or unchecks the item, removing/adding the check-mark.
- Then, invokes the menu-item-action-function associated with the
- check-menu-item with one parameter - the window-menu-item.
-
-
- |#
-
- (defclass check-menu-item (menu-item)
- ((check-mark-char :initarg :mark))
- (:default-initargs :mark #\CheckMark))
-
- (defclass check-window-menu-item (window-menu-item check-menu-item) ())
-
- (defmethod containing-view ((menu-item check-menu-item))
- ;; find the root of the chain of hier-marking menus
- (let ((owner (slot-value menu-item 'ccl::owner)))
- (if owner (containing-view owner) menu-item)))
-
- (defmethod containing-view ((menu-item check-menu-item))
- ;; find the root of the chain of hier-marking menus
- (let ((owner (menu-item-owner menu-item)))
- (if owner (containing-view owner) menu-item)))
-
- ;; specialize this to take other actions after checking a menu item
-
- (defmethod initialize-instance ((menu-item check-menu-item) &rest initargs)
- (apply #'call-next-method menu-item initargs)
- (with-slots (check-mark-char) menu-item
- (set-check-mark-char menu-item check-mark-char)))
-
- (defmethod do-menu-item-action ((menu-item check-menu-item) &optional param)
- (declare (ignore param))
- (let ((menu-item-action (menu-item-action-function menu-item)))
- (set-menu-item-check-mark menu-item
- (if (menu-item-check-mark menu-item)
- nil
- (slot-value menu-item 'check-mark-char)))
- (when menu-item-action (funcall menu-item-action))))
-
-
-
- (defmethod do-menu-item-action ((menu-item check-window-menu-item) &optional param)
- (let ((menu-item-action (menu-item-action-function menu-item)))
- (set-menu-item-check-mark menu-item
- (if (menu-item-check-mark menu-item)
- nil
- (slot-value menu-item 'check-mark-char)))
- (when menu-item-action (funcall menu-item-action param))))
-
- (defmethod set-menu-item-check-mark ((menu-item check-menu-item) mark)
- ;; uncheck the item if mark is nil
- ;; check the item if mark is not nil
- ;; if mark is not t, set the character
- ;; otherwise use the check-mark-char associated with the item.
- (with-slots (check-mark-char) menu-item
- (cond ((equal mark t)
- (call-next-method menu-item check-mark-char))
- ((null mark)
- (call-next-method menu-item nil))
- (t (set-check-mark-char menu-item mark)
- (call-next-method menu-item check-mark-char)))))
-
- (defmethod set-check-mark-char ((menu-item check-menu-item) mark)
- ;; Set the mark associated with a check mark for a menu item
- ;; When mark is
- ;; a character, set the check mark char to the character
- ;; an integer (0 - 255), set the char to the character with the integer code
- ;; a string, set the mark to the first character of the string
- ;; otherwise set the mark to #\checkMark
- (let ((type (type-of mark)))
- (setf (slot-value menu-item 'check-mark-char)
- (cond ((stringp mark) (char mark 0))
- ((equal type 'character) mark)
- ((equal type 'standard-char) mark)
- ((and (equal type 'fixnum) (<= 0 mark 255))
- (code-char mark))
- (t #\CheckMark)))))
-